/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DiffWin.java
 *
 * Created on 15.12.2009, 0:07:40
 */

package drivemachine;

import drivemachine.data2.CompareEntry;
import drivemachine.data2.Entry;
import java.awt.Color;
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;

/**
 *
 * @author positron
 */
public class DiffWin extends javax.swing.JDialog {

	public DriveTreeModel compModel;
	private DefaultTreeCellRenderer renderer;
	private static final Color DARK_GREEN = new Color(0x008800);
	private static final Color DARK_RED = new Color(0x880000);
    /** Creates new form DiffWin */
    public DiffWin(Comparator cmp) {
		setTitle("Comparing "+cmp.getSide(0)+" to "+cmp.getSide(1) );
		compModel = new DriveTreeModel();
		renderer = new DefaultTreeCellRenderer() {
			@Override
			public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
				JLabel res = (JLabel)super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
				//TODO: add some fake Entry
				long ss = 0;
				if(value instanceof Entry) {
					Entry cc = (Entry)value;
					ss = cc.getFullSize();					
				} else
				if(value instanceof DriveTreeModel.SelfEntry) {
					ss = ((DriveTreeModel.SelfEntry)value).size;
				}
				if(ss > 1024*1024*1024) res.setForeground(Color.RED); else
				if(ss > 1024*1024*30) res.setForeground(DARK_RED); else
				if(ss < -1024*1024*200) res.setForeground(Color.GREEN); else
				if(ss < 0) res.setForeground(DARK_GREEN);
				return res;
			}
		};

		renderer.setLeafIcon(MainWin.FOLDER_ICON);
		renderer.setClosedIcon(MainWin.FOLDER_ICON);
		renderer.setOpenIcon(MainWin.FOLDER_OPEN_ICON);
		initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tree = new javax.swing.JScrollPane();
        jTree1 = new javax.swing.JTree();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Difference");

        jTree1.setModel(compModel);
        jTree1.setCellRenderer(renderer);
        tree.setViewportView(jTree1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tree, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tree, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTree jTree1;
    private javax.swing.JScrollPane tree;
    // End of variables declaration//GEN-END:variables

}
